package cn.edu.jxau.test;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.Objects;

/**
 * @author Fudashi
 */
public class Main {

	public static void main(String[] args) {

		System.out.println(foo("abaccdeff"));
	}

	public static char foo(String str) {

		Objects.requireNonNull(str, "参数str不能为null");
		if (str.length() == 0) {
			throw new IllegalArgumentException("参数str是个空串");
		}
		LinkedHashMap<Character, Integer> map = new LinkedHashMap<>();
		for (int i = 0, end = str.length(); i < end; i++) {
			char ch = str.charAt(i);
			Integer counter = map.get(ch);
			if (counter == null) {
				map.put(ch, 1);
			} else {
				map.put(ch, ++counter);
			}
		}
		for (Iterator<Entry<Character, Integer>> iterator = map.entrySet().iterator(); iterator.hasNext();) {
			Entry<Character, Integer> entry = iterator.next();
			if (entry.getValue() == 1) {
				return entry.getKey();
			}
		}
		return 0;
	}
}
